package com.uw.uwregistry.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;

@Slf4j
public class IpUtil {

    private IpUtil() {
    }

    public static String getHost() {
        String host = "";
        try (InetUtils inetUtils = new InetUtils(new InetUtilsProperties());) {
            host = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
        } catch (Exception ex) {
            log.error("获取本机IP地址失败", ex);
            host = "127.0.0.1";
        }
        return host;
    }
}
